<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>mlock</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_000_007_678">&nbsp;</a>NAME</h4><blockquote>
mlock, munlock - lock or unlock a range of process address space
(<b>REALTIME</b>)
</blockquote><h4><a name = "tag_000_007_679">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="sysmman.h.html">sys/mman.h</a>&gt;

int mlock(const void * <i>addr</i>, size_t <i>len</i>);
int munlock(const void * <i>addr</i>, size_t <i>len</i>);
</code>
</pre>
</blockquote><h4><a name = "tag_000_007_680">&nbsp;</a>DESCRIPTION</h4><blockquote>
The function
<i>mlock()</i>
causes those whole pages containing any part of the
address space of the process starting at address
<i>addr</i>
and continuing for
<i>len</i>
bytes to be memory resident
until unlocked or until the process exits or
<i>exec</i>s
another process image.
The implementation may require that
<i>addr</i>
be a multiple of {PAGESIZE}.
<p>
The function
<i>munlock()</i>
unlocks those whole pages containing any part of the
address space
of the process starting at address
<i>addr</i>
and continuing for
<i>len</i>
bytes, regardless of how many times
<i>mlock()</i>
has been called by the process
for any of the pages in the specified range.
The implementation may require that
<i>addr</i>
be a multiple of the {PAGESIZE}.
<p>
If any of the pages in the range specified to a call to
<i>munlock()</i>
are also mapped into the address spaces of other processes,
any locks established on those pages by another process
are unaffected by the call of this process to
<i>munlock()</i>.
If any of the pages in the range specified by a call to
<i>munlock()</i>
are also mapped into other portions of the address space
of the calling process outside the range specified,
any locks established on those pages via the other mappings
are also unaffected by this call.
<p>
Upon successful return from
<i>mlock()</i>,
pages in the specified range will be locked and memory resident.
Upon successful return from
<i>munlock()</i>,
pages in the specified range will be unlocked with respect to the
address space of the process.
Memory residency of unlocked pages is unspecified.
<p>
The appropriate privilege is required to lock process memory with
<i>mlock()</i>.
</blockquote><h4><a name = "tag_000_007_681">&nbsp;</a>RETURN VALUE</h4><blockquote>
Upon successful completion, the
<i>mlock()</i>
and
<i>munlock()</i>
functions return a value of zero.
Otherwise, no change is made to any locks in the
address space of the process, and the function 
returns a value of -1 and sets
<i>errno</i>
to indicate the error.
</blockquote><h4><a name = "tag_000_007_682">&nbsp;</a>ERRORS</h4><blockquote>
The 
<i>mlock()</i>
and
<i>munlock()</i>
functions will fail if:
<dl compact>

<dt>[ENOMEM]<dd>
Some or all of the address range specified by the
<i>addr</i>
and
<i>len</i>
arguments does not correspond to valid mapped pages in the
address space of the process.

<dt>[ENOSYS]<dd>
The implementation does not support this memory locking interface.

</dl>
<p>
The 
<i>mlock()</i>
functions will fail if:
<dl compact>

<dt>[EAGAIN]<dd>
Some or all of the memory identified by the operation could not be locked
when the call was made.

</dl>
<p>
The 
<i>mlock()</i>
and
<i>munlock()</i>
functions may fail if:
<dl compact>

<dt>[EINVAL]<dd>
The
<i>addr</i>
argument is not a multiple of {PAGESIZE}.

</dl>
<p>
The 
<i>mlock()</i>
function may fail if:
<dl compact>

<dt>[ENOMEM]<dd>
Locking the pages mapped by the specified range would
exceed an implementation-dependent limit on the
amount of memory that the process may lock.

<dt>[EPERM]<dd>
The calling process does not have the appropriate privilege to perform the
requested operation.

</dl>
</blockquote><h4><a name = "tag_000_007_683">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_684">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_685">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="exec.html">exec</a></i>,
<i><a href="_exit.html">_exit()</a></i>,
<i><a href="fork.html">fork()</a></i>,
<i><a href="mlockall.html">mlockall()</a></i>,
<i><a href="munmap.html">munmap()</a></i>,
<i><a href="sysmman.h.html">&lt;sys/mman.h&gt;</a></i>.
</blockquote><h4>DERIVATION</h4><blockquote>
Derived from the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995)
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>

